package com.yykj.user.center.server.utils;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @author chenl
 * @version 1.0
 * @date 2021/10/31 20:02
 */
public class DateUtil {

    public static String dateTime2TimeString(LocalDateTime localDateTime){
        DateTimeFormatter dtf2 = DateTimeFormatter.ofPattern("HH:mm");
        String time = dtf2.format(localDateTime);
        return time;
    }

    public static String dateTime2String(LocalDateTime localDateTime){
        DateTimeFormatter dtf2 = DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH:mm");
        String dateTime = dtf2.format(localDateTime);
        return dateTime;
    }

    public static String dateTime2DateString(LocalDateTime localDateTime){
        DateTimeFormatter dtf2 = DateTimeFormatter.ofPattern("yyyyMMdd");
        String dateTime = dtf2.format(localDateTime);
        return dateTime;
    }

    public static LocalDate stringDate2Date(String date){
        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        return LocalDate.parse(date, fmt);
    }

    public static String localDate2StringLocalDate(LocalDate localDate){
        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        return fmt.format(localDate);
    }

    public static LocalDateTime stringDateTime2DateTime(String dateTime){
        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        return LocalDateTime.parse(dateTime, fmt);
    }

    public static String dateTimeToString(LocalDateTime localDateTime){
        DateTimeFormatter dtf2 = DateTimeFormatter.ofPattern("yyyy.MM.dd HH:mm");
        String dateTime = dtf2.format(localDateTime);
        return dateTime;
    }
    public static String dateTimeToHourMinutes(LocalDateTime localDateTime){
        DateTimeFormatter dtf2 = DateTimeFormatter.ofPattern("HH:mm");
        String dateTime = dtf2.format(localDateTime);
        return dateTime;
    }

    public static String dateTime2StringDateTime(LocalDateTime dateTime){
        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        return fmt.format(dateTime);
    }
}
